package MODELE.DONNEE;

import java.util.ArrayList;
import java.util.Iterator;

public class ChampColonne extends Donnee {

	private String designation;
	public ArrayList<Double> listedemontant = new ArrayList<Double>();
	
	public static ArrayList<Donnee> miseAniveaux(ArrayList<Donnee> data,int min,int max){
		int courant = min;

		for (Iterator iterator = data.iterator(); iterator.hasNext();) {
			Donnee donnee = (Donnee) iterator.next();
			if (donnee instanceof ChampColonne) {
				ChampColonne chc = (ChampColonne) donnee;
				String str = chc.getDesignation();
				if(str.length()>=max){
					courant = max;
					break;
				}else if(str.length()>courant){
					courant = str.length();
				}
			}
		}
		
		for (Iterator iterator = data.iterator(); iterator.hasNext();) {
			Donnee donnee = (Donnee) iterator.next();
			if (donnee instanceof ChampColonne) {
				ChampColonne chc = (ChampColonne) donnee;
				String str = chc.getDesignation();
				if(str.length()>max){
					str = str.substring(0,max);
				}else if(str.length()<courant){
					for (int i = 0; i < (courant-str.length()) ; i++) {
						str+=" ";
					}
				}
				chc.setDesignation(str);
			}
		}
		return data;
	}
	
	public ChampColonne(int nbColonne){
		this.designation = "A remplir ";
		this.initListemontant(nbColonne);
	}
	
	public ChampColonne(String Designation, int nbColonne){
		this.designation = Designation;
		this.initListemontant(nbColonne);
	}

	private void initListemontant(int nbColonne){
		for (int i = 0; i < nbColonne; i++) {
			this.listedemontant.add((double) 0);
		}
	}
	public String getDesignation() {
		return designation;
	}

	public void setDesignation(String Designation) {
		designation = Designation;
	}

	public ArrayList<Double> getListedemontant() {

		return listedemontant;
	}

	public void setListedemontant(ArrayList<Double> Listedemontant) {

		listedemontant = Listedemontant;
	}
	
	public int getNbColonne(){
		return this.listedemontant.size();
	}

	@Override
	public String toString() {
		return designation + " | " + listedemontant + "]\r\n";
	}
}
